console.log("4RBush");
let utils = data["utils"];
let RBushItem = data["RBushItem"];
let RBU = data["RBU"];

function RBush(maxEntries, format) {
  if (!(this instanceof RBush)) return new RBush(maxEntries, format);
  this._maxEntries = Math.max(4, maxEntries || 9);
  this._minEntries = Math.max(2, Math.ceil(.4 * this._maxEntries));
  this.clear();
}

utils.extend(RBush.prototype, {
  all: function () {
    return this._all(this.data, []);
  },
  search: function (bbox) {
    var node = this.data,
      result = [],
      toBBox = this.toBBox;
    if (!RBU.intersects(bbox, node)) return result;
    for (var i, len, child, childBBox, nodesToSearch = []; node;) {
      for (i = 0, len = node.children.length; i < len; i++) {
        child = node.children[i];
        childBBox = node.leaf ? toBBox(child) : child;
        RBU.intersects(bbox, childBBox) && (node.leaf ? result.push(child) : RBU.contains(bbox, childBBox) ? this._all(child, result) : nodesToSearch.push(child));
      }
      node = nodesToSearch.pop();
    }
    return result;
  },
  insert: function (item) {
    item && this._insert(item, this.data.height - 1);
    return this;
  },
  clear: function () {
    this.data = RBU.createNode([]);
    return this;
  },
  toBBox: function (item) {
    return item;
  },
  compareMinX: RBU.compareNodeMinX,
  compareMinY: RBU.compareNodeMinY,
  toJSON: function () {
    return this.data;
  },
  fromJSON: function (data) {
    this.data = data;
    return this;
  },
  _all: function (node, result) {
    for (var nodesToSearch = []; node;) {
      node.leaf ? utils.merge(result, node.children) : utils.merge(nodesToSearch, node.children);
      node = nodesToSearch.pop();
    }
    return result;
  },
  _build: function (items, left, right, height) {
    var node, N = right - left + 1,
      M = this._maxEntries;
    if (N <= M) {
      node = RBU.createNode(items.slice(left, right + 1));
      RBU.calcBBox(node, this.toBBox);
      return node;
    }
    if (!height) {
      height = Math.ceil(Math.log(N) / Math.log(M));
      M = Math.ceil(N / Math.pow(M, height - 1));
    }
    node = RBU.createNode([]);
    node.leaf = !1;
    node.height = height;
    var i, j, right2, right3, N2 = Math.ceil(N / M),
      N1 = N2 * Math.ceil(Math.sqrt(M));
    multiSelect(items, left, right, N1, this.compareMinX);
    for (i = left; i <= right; i += N1) {
      right2 = Math.min(i + N1 - 1, right);
      multiSelect(items, i, right2, N2, this.compareMinY);
      for (j = i; j <= right2; j += N2) {
        right3 = Math.min(j + N2 - 1, right2);
        node.children.push(this._build(items, j, right3, height - 1));
      }
    }
    RBU.calcBBox(node, this.toBBox);
    return node;
  },
  _chooseSubtree: function (bbox, node, level, path) {
    for (var i, len, child, targetNode, area, enlargement, minArea, minEnlargement; ;) {
      path.push(node);
      if (node.leaf || path.length - 1 === level) break;
      minArea = minEnlargement = 1 / 0;
      for (i = 0, len = node.children.length; i < len; i++) {
        child = node.children[i];
        area = RBU.bboxArea(child);
        enlargement = RBU.enlargedArea(bbox, child) - area;
        if (enlargement < minEnlargement) {
          minEnlargement = enlargement;
          minArea = area < minArea ? area : minArea;
          targetNode = child;
        } else if (enlargement === minEnlargement && area < minArea) {
          minArea = area;
          targetNode = child;
        }
      }
      node = targetNode || node.children[0];
    }
    return node;
  }
})



return {
  "utils": utils,
  "RBushItem": RBushItem,
  "RBU": RBU,
  "RBush": RBush
}